Xbasic

Array set_recycle Method

Syntax

V <array>.set_recycle(recycle as L)

Arguments

recycleLogical

A .t. or .f. value that enables or disables array recycling.

Description

Enables or disable array element recycling.

Discussion

The <array>.set_recycle() method controls the recycling behavior for dynamic arrays. When an array element is added using the [] operator, if the last element in the array is empty, Alpha Anywhere does not add a new element. For example:

dim arr[0] as N
for i = 1 to 10
    arr[] = 0
next

? arr
= [1] = 0
Prefer to use <array>.append() with property arrays as using [] to add elements to a property array can lead to unintentional bugs if the [..] operator is accidentally omitted.

In some situations, this behavior is not desired. Array recycling can be disabled by calling <array>.set_recycle() with a value of .f.. When recycling is disabled, Alpha Anywhere will always add a new element to an array when using the [] operator.

dim arr[0] as N
arr.set_recycle(.f.)
for i = 1 to 10
    arr[] = 0
next

? arr
= [1] = 0
[2] = 0
[3] = 0
[4] = 0
[5] = 0
[6] = 0
[7] = 0
[8] = 0
[9] = 0
[10] = 0

If elements are added to an array using the <array>.append() method, recycling is not used. Alpha Anywhere will always add an element to an array using the <array>.append() method.

dim arr2[0] as N 
for i = 1 to 10
    x = arr2.append()
    arr2[x] = 0
next

? arr2
= [1] = 0
[2] = 0
[3] = 0
[4] = 0
[5] = 0
[6] = 0
[7] = 0
[8] = 0
[9] = 0
[10] = 0

See Also